package com.offcn.bigdata.datastream.transformation

import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
import org.apache.flink.streaming.api.scala._
/**
 * @Auther: BigData-LGW
 * @ClassName: UnionAndConnect
 * @Date: 2020/12/16 20:28
 * @功能描述: $FunctionDescription
 * @Version:1.0
 */
/**
 * 流的合并union和流的链接connect
 *      union:流的合并，就是前面学习过的sql中的union all
 *      connect：流的连接,仅仅是把两个流连接成一个具有两个互相独立部分的流的集合
 */
object UnionAndConnect {
    def main(args: Array[String]): Unit = {
        val env = StreamExecutionEnvironment.getExecutionEnvironment
        val left = env.fromCollection(1 to 50)
        val right = env.fromCollection(4 until 8)
        val unioned = left.union(right)
        unioned.print("union:::")
        val connected:ConnectedStreams[Int,Int] = left.connect(right)
        connected.map((leftNum:Int) => "left>>>" + (leftNum*2),(rightNum:Int) => "right>>>"+(rightNum*3))
                .print("connect:::")
        env.execute(s"${UnionAndConnect.getClass.getSimpleName}")
    }
}
